<!DOCTYPE html>
<html lang="zh-cn">

<head>

  <meta content="text/html;charset=utf-8" http-equiv="content-type">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">

  <title>滑雪族 - 订单查询</title>

  <!-- Bootstrap Core CSS -->
<!-- MetisMenu CSS -->
<!-- Custom CSS -->
<!-- Custom Fonts -->
  <!-- Timeline CSS -->  <!-- Custom Fonts -->
  <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
  <![endif]-->

    <link rel="stylesheet" href="/server/r/bower_components/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/server/r/bower_components/metisMenu/dist/metisMenu.min.css" />
    <link rel="stylesheet" href="/server/r/static/css/sb-admin-2_e507c2b.css" />
    <link rel="stylesheet" type="text/css" href="/server/r/bower_components/font-awesome/css/font-awesome.min.css" />
    <link type="text/css" rel="stylesheet" href="/server/r/static/css/hxz/common_2baa698.css" />
    <link rel="stylesheet" href="/server/r/static/css/timeline_1c13c9f.css" />
    <link rel="stylesheet" type="text/css" href="/server/r/bower_components/alertify/themes/alertify.core.css" />
    <link rel="stylesheet" type="text/css" href="/server/r/bower_components/alertify/themes/alertify.bootstrap.css" />
    <link type="text/css" rel="stylesheet" href="/server/r/bower_components/select2/dist/css/select2.min.css" />
</head>

<body><div id="wrapper">


  <!--场次二维码的模态窗口-->
  <div class="modal fade" id="apply-refund-dialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
       aria-hidden="true">
    <div class="modal-dialog" style="width: 450px;">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title">申请退款</h4>
        </div>
        <div class="modal-body">
          <form id="option-edit-form" role="form">
            <input type="hidden" id="apply-order-id">

            <div class="form-group form-inline form-require">
              <label class="control-label">订单号：</label>
              <label class="control-label" id="apply-refund-code"></label>
            </div>
            <div class="form-group form-inline form-require">
              <label class="control-label">订单状态：</label>
              <label class="control-label" id="apply-refund-status"></label>
            </div>
            <div class="form-group form-inline form-require">
              <label class="control-label">订单总价：</label>
              <label class="control-label" id="apply-refund-totalPrice"></label>
            </div>
            <div class="form-group form-inline form-require">
              <label class="control-label">支付金额：</label>
              <label class="control-label" id="apply-refund-price"></label>
              <label class="control-label">元</label>
            </div>
            <div class="form-group form-inline form-require">
              <label class="control-label">购买数量：</label>
              <label class="control-label" id="apply-refund-chargeNum"></label>
            </div>
            <div class="form-group form-inline form-require">
              <label class="control-label">可用数量：</label>
              <label class="control-label" id="apply-refund-availableCount"></label>
            </div>
            <div class="form-group form-inline form-require">
              <label class="control-label">退款金额：</label>
              <input class="form-control input-sm" id="apply-refund-money" type="text"
                     maxlength="4" placeholder="请输入退款金额" style="width: 100px;">元

              <p class="help-block font-small">
                当可用数量大于0的时候，退款金额默认为该订单的可用数量*单价,<br>
                当可用数量为0的时候，说明订单已经全部核销，退款金额默认为订单总价。<br>
                用户可以根据实际情况修改退款的金额。
              </p>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <a id="option-refund-btn" href="javascript:void(0);" type="button" class="btn btn-success">确定</a>
          <button type="button" class="btn btn-success btn-outline" data-dismiss="modal" aria-hidden="true">取消</button>
        </div>
      </div>
      <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
  </div>
  <!--场次二维码的模态窗口-->

  <!-- Navigation -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">

    <div class="navbar-header">
  <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
  <a class="navbar-brand" href="activity-list">滑雪族 管理</a>
</div>
<!-- /.navbar-header -->

<ul class="nav navbar-top-links navbar-right">
  <!-- /.dropdown -->
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
    </a>
    <ul class="dropdown-menu dropdown-user">
      <li><a href="/manage/logout"><i class="fa fa-sign-out fa-fw"></i> 退出系统</a>
      </li>
    </ul>
    <!-- /.dropdown-user -->
  </li>
  <!-- /.dropdown -->
</ul>
<!-- /.navbar-top-links -->

    <div class="navbar-default sidebar" role="navigation">
      <div class="sidebar-nav navbar-collapse">
        <ul class="nav" id="side-menu">
  <li>
    <a href="#"><i class="fa fa-asterisk fa-fw"></i> 产品管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/activity-list"> 产品查询</a>
      </li>
      <li>
        <a href="/manage/manage-organizer-render-activity"> 产品显示控制</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="/#"><i class="fa fa-male fa-fw"></i> 报名管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/player-list"> 报名查询</a>
      </li>
    </ul>
  </li>
  <li>
    <a href="#"><i class="fa fa-list-alt fa-fw"></i> 订单管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/order-list"> 订单查询</a>
      </li>
      <li>
        <a href="/manage/refund-list"> 退款管理</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-check-circle fa-fw"></i> 主办方认证<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/organizer-edit"> 创建主办方</a>
      </li>
      <li>
        <a href="/manage/organizer-list"> 主办方列表</a>
      </li>
      <li>
        <a href="/manage/organizer-print"> 冬令营打印设置</a>
      </li>

    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-picture-o fa-fw"></i> 雪场管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/ski-field-edit"> 创建雪场</a>
      </li>
      <li>
        <a href="/manage/ski-field-list"> 雪场列表</a>
      </li>

    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-users fa-fw"></i> 教练管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/coach-list"> 预约情况</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-credit-card fa-fw"></i> 结算管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/manage-transfer-list"> 转账管理</a>
      </li>
      <li>
        <a href="/manage/manage-withdrawals-apply-list"> 提现申请</a>
      </li>
      <li>
        <a href="/manage/manage-withdrawals-record-list"> 结算列表</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-rmb fa-fw"></i> 财务管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/stream-list"> 交易流水</a>
      </li>
      <li>
        <a href="/manage/manage-bill-record-list"> 对账列表</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-dollar fa-fw"></i> 营销管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/marketing-list"> 返利管理</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-comments fa-fw"></i> 评价管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/comment-list">评价管理</a>
      </li>
    </ul>
  </li>
  <li>
    <a href="#"><i class="fa fa-tasks fa-fw"></i> 定时处理管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/quartz-list"> 定时处理列表</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
  <li>
    <a href="#"><i class="fa fa-wechat fa-fw"></i> 微信页面管理<span class="fa arrow"></span></a>
    <ul class="nav nav-second-level">
      <li>
        <a href="/manage/typography-list"> 微信首页管理</a>
      </li>
      <li>
        <a href="/manage/activity-weight-manage"> 活动置顶</a>
      </li>
    </ul>
    <!-- /.nav-second-level -->
  </li>
</ul>
      </div>
      <!-- /.sidebar-collapse -->
    </div>
    <!-- /.navbar-static-side -->
  </nav>


  <div id="page-wrapper">
    <div class="row">
      <div class="col-lg-12">
        <h3 class="page-header">订单查询</h3>
      </div>
      <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="form-inline">
      <div class="form-group">
        <label>产品名称：</label>
        <select class="form-control" id="order-activity"></select>
      </div>
      <div class="form-group" id="episode-form-group" style="display: none;">
        <label>子项目：</label>
        <select class="form-control" id="order-episode"></select>
      </div>
    </div>
    <div class="form-inline">
      <div class="form-group">
        <label>联系电话：</label>
        <input class="form-control input-sm" id="order-phone" value="${(phone)!''}">
      </div>
      <div class="form-group">
        <label>订单号：</label>
        <input class="form-control input-sm" id="order-num">
      </div>
      <div class="form-group">
        <label>状态：</label>
        <select class="form-control" id="order-status"></select>
      </div>
      <div class="form-group">
        <a id="order-filter" href="javascript:void(0);" type="button" class="btn btn-sm btn-success btn-outline">查询</a>
        <a id="order-filter-all" href="javascript:void(0);" type="button"
           class="btn btn-sm btn-success btn-outline">全部</a>
      </div>
    </div>
    <!-- /.row -->
    <div class="row" id="order-list-panel" style="display: none;">
      <div class="col-lg-12">
        <div class="panel panel-default">
          <div class="panel-heading">
            订单列表
            <div class="pull-right">
              (共：<label id="plays"></label>个订单)
            </div>
          </div>
          <!-- /.panel-heading -->
          <div class="panel-body">
            <div class="dataTable_wrapper">
              <table class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                  <th>订单ID</th>
                  <th>订单号</th>
                  <th>下单用户</th>
                  <th>联系电话</th>
                  <th>创建时间</th>
                  <th>产品</th>
                  <th>子项目</th>
                  <th>购买数量</th>
                  <th>订单总金额</th>
                  <th>订单状态</th>
                  <th>订单来源</th>
                  <th>操作</th>
                </tr>
                </thead>
                <tbody id="order-list-body">

                </tbody>
              </table>

              <div class="pagination dataTables_paginate paging_simple_numbers pull-right" id="pagination" role="status"
                   aria-live="polite">
              </div>
            </div>

          </div>
          <!-- /.panel-body -->
        </div>
        <!-- /.panel -->
      </div>
      <!-- /.col-lg-12 -->

    </div>

  </div>
  <!-- /#page-wrapper -->

</div>
<!-- /#wrapper --><script id="tpl-order-list-item" type="text/template">
  <tr>
    <td>{{orderId}}</td>
    <td>{{code}}</td>
    <td>{{name}}</td>
    <td>{{phone}}</td>
    <td>{{datetime(createTime)}}</td>
    <td>{{title}}</td>
    <td>{{episodeName}}</td>
    <td>{{chargeNum}}</td>
    <td>{{totalPrice}}元</td>
    <td>{{orderStatus2String(orderStatus)}}</td>
    <td>{{clientName(client)}}</td>
    <td>
      <a href="/manage/order-detail?orderId={{orderId}}" type="button" class="btn btn-info btn-xs">订单详情</a>
      <% if (orderStatus == 1 || orderStatus == 5) { %>
      <% if (totalPrice > 0 ) {%>
      <a type="button" data-code="{{orderId}}" class="btn btn-fix btn-success  btn-xs apply-refund">申请退款</a>
      <% } %>
      <% } %>
    </td>
  </tr>
</script>
<div id="hxz-background" class="background" style="display: none; "></div>
<div id="hxz-progressBar" class="progressBar" style="display: none; ">数据加载中，请稍等...</div>

<script src="/server/r/require.js"></script>
<script type="text/javascript">/*resourcemap*/
require.config({paths:{
  "r/bower_components/jquery/dist/jquery.min": "/server/r/bower_components/jquery/dist/jquery.min",
  "r/bower_components/underscore/underscore-min": "/server/r/bower_components/underscore/underscore-min",
  "r/static/js/hxz/hxz.valid": "/server/r/static/js/hxz/hxz.valid_12cc206",
  "r/static/js/hxz/hxz.rest": "/server/r/static/js/hxz/hxz.rest_07c8105",
  "r/bower_components/alertify/alertify.min": "/server/r/bower_components/alertify/alertify.min",
  "r/static/js/alertify-config": "/server/r/static/js/alertify-config_0cc8db2",
  "r/bower_components/bootstrap/dist/js/bootstrap.min": "/server/r/bower_components/bootstrap/dist/js/bootstrap.min",
  "r/bower_components/metisMenu/dist/metisMenu.min": "/server/r/bower_components/metisMenu/dist/metisMenu.min",
  "r/bower_components/select2/dist/js/select2": "/server/r/bower_components/select2/dist/js/select2",
  "r/static/js/hxz/hxz.ui": "/server/r/static/js/hxz/hxz.ui_0a7714d",
  "r/static/js/hxz/hxz": "/server/r/static/js/hxz/hxz_589b155",
  "r/vendor/pagination/jquery.pagination": "/server/r/vendor/pagination/jquery.pagination"
}});

  var organizerListMap = {};
  organizerListMap = ${organizerListMap};



  var pagination = false;
  var orderListFilter = {};

  require(["r/bower_components/jquery/dist/jquery.min", "r/static/js/hxz/hxz", "r/vendor/pagination/jquery.pagination", "r/bower_components/select2/dist/js/select2", "r/static/js/alertify-config"], function ($, hxz, pagination, select2, alertify) {

    function fetchOption() {

      hxz.activityOptionGroup("#order-activity", "#order-episode", 0, 1);

      var statusData = [
        {"id": 999, "text": "全部"},
        {"id": 0, "text": "未支付"},
        {"id": 1, "text": "可使用"},
        {"id": 2, "text": "退款中"},
        {"id": 3, "text": "已退款"},
        {"id": 4, "text": "已关闭"},
        {"id": 5, "text": "已完成"}
      ];

      $("#order-status").select2({
        language: "zh-CN",
        placeholder: "订单状态",
        width: "100",
        data: statusData
      });
    }

    function fetchOrderList(page) {
      $("#order-list-panel").css("display", "");

      var apiOrderList = hxz.RestApi.manageOrderList;

      if (!page) {
        page = "1";
      }

      apiOrderList = apiOrderList + "?page=" + page;

      if (orderListFilter && orderListFilter.activityId && orderListFilter.activityId !== "0") {
        apiOrderList = apiOrderList + "&activityId=" + orderListFilter.activityId;
      }

      if (orderListFilter && orderListFilter.episodeId && orderListFilter.episodeId !== "0") {
        apiOrderList = apiOrderList + "&episodeId=" + orderListFilter.episodeId;
      }

      if (orderListFilter && orderListFilter.status && orderListFilter.status !== "999") {
        apiOrderList = apiOrderList + "&status=" + orderListFilter.status;
      }

      if (orderListFilter && orderListFilter.code) {
        apiOrderList = apiOrderList + "&code=" + orderListFilter.code;
      }

      if (orderListFilter && orderListFilter.phone) {
        apiOrderList = apiOrderList + "&phone=" + orderListFilter.phone;
      }

      hxz.doGet({url: apiOrderList}, function (data) {

        if (data.status == "0") {
          return alertify.log("系统错误");
        }
        $("#plays").html("").append(data.data.list.result.totalCount);
        render(data.data.list.result.list, page, data.data.list.result.totalCount);
      });
    }

    function render(dataList, page, count) {

      var tpl = _.template($('#tpl-order-list-item').html());
      $("#order-list-body").html("");
      for (var i = 0; i < dataList.length; i++) {
        var _data = dataList[i];

        _data.orderIndex = hxz.pageIndex(i, page);
        _data.datetime = hxz.datetime;
        _data.clientName = function (data) {
          if (data != 0) {
            return organizerListMap[data];
          } else {
            return "滑雪族";
          }
        };


        _data.showRefundButton = function (data) {
          if (data > new Date().getTime()) {
            return true;
          }
          return false;
        };

        _data.orderStatus2String = function (data) {
          data = Number(data);
          return hxz.orderStatus(data);
        };

        $("#order-list-body").append(tpl(_data));
      }

      if (pagination) {
        pagination = false;

        $('#pagination').pagination(count, {
          current_page: 0,
          items_per_page: 10,
          num_display_entries: 6,
          callback: function (page_id) {
            //模拟ajax去后端读取页数，获取数据并渲染列表的过程
            fetchOrderList(page_id + 1);
          },
          load_first_page: false,
          prev_text: '上一页',
          next_text: '下一页'
        });
      }

    }

    function event() {

      $("#option-refund-btn").click(function () {

        var data = {
          orderId: $("#apply-order-id").val(),
          refundPrice: $("#apply-refund-money").val()
        };

        if (isNaN(data.orderId)) {
          return alertify.error("退款金额必须为数字", "danger");
        }

//        if ($("#apply-refund-money").val() > $("#apply-refund-price").html()) {
//          return alertify.error("退款金额不能超过支付金额", "danger");
//        }

        hxz.doPost({url: hxz.RestApi.manageApplyRefund, data: data}, function (data) {
          if (data.status == "1") {
            alertify.log(data.msg);
            fetchOrderList(1);
            $("#apply-refund-dialog").modal('hide');
          } else {
            return alertify.error(data.msg, "danger");
          }
        });
      });


      $("#order-list-body").on("click", ".apply-refund", function () {
        var data = {
          orderId: $(this).data("code")
        };
        hxz.doPost({url: hxz.RestApi.manageOrderDetail, data: data}, function (data) {
          if (data.status == "1") {
            $("#apply-order-id").val(data.data.order.orderId);
            var price = (parseFloat(data.data.order.totalPrice) - parseFloat(data.data.order.reduce)).toFixed(2);
            $("#apply-refund-code").html("").html(data.data.order.code);
            $("#apply-refund-status").html("").html(hxz.orderStatus(data.data.order.orderStatus));
            $("#apply-refund-totalPrice").html("").html(data.data.order.totalPrice + "元");
            $("#apply-refund-price").html("").html(price);
            $("#apply-refund-chargeNum").html("").html(data.data.order.chargeNum + " 张");
            $("#apply-refund-availableCount").html("").html(data.data.order.availableCount + " 张");
            if (data.data.order.availableCount > 0) {
              var refundMoney = (data.data.order.availableCount * parseFloat(data.data.order.price)
                  - (data.data.order.availableCount / data.data.order.chargeNum) * parseFloat(data.data.order.reduce)).toFixed(2);
              $("#apply-refund-money").val(refundMoney);
            } else {
              $("#apply-refund-money").val(parseFloat(data.data.order.totalPrice).toFixed(2) - parseFloat(data.data.order.reduce).toFixed(2));
            }
            $("#apply-refund-dialog").modal('show');
          } else {
            return alertify.error(data.msg, "danger");
          }
        });

      });


      $("#order-filter-all").unbind("click").on("click", function () {
        window.location.href = "/manage/order-list";
      });

      $("#order-filter").unbind("click").on("click", function () {
        orderListFilter = {};
        orderListFilter.status = $("#order-status").val();
        orderListFilter.activityId = $("#order-activity").val();
        orderListFilter.episodeId = $("#order-episode").val();
        orderListFilter.code = $("#order-num").val();
        orderListFilter.phone = $("#order-phone").val();
        pagination = true;
        fetchOrderList(1);
      });
    }

    function pageInit() {
      pagination = true;
      fetchOption();
      orderListFilter.phone = $("#order-phone").val();
      fetchOrderList(1);
      event();
    }

    // 执行初始化
    pageInit();

  });
</script>
</body>
</html>